package com.ebs.md.fxmonitor.marketmonitor.model;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/model/AbsOBState.java $
 *  $Revision: #4 $  $Change: 116131 $  $DateTime: 2012/10/23 12:55:07 $  $Author: Arik.Sher $
 */

import java.io.Serializable;

import com.ebs.md.api.BookSide;
import com.ebs.md.api.Rate;
import com.ebs.md.api.product.PairProduct;


public abstract class AbsOBState
implements Serializable
{
	//gened serial id.
	private static final long serialVersionUID = -2244514309690214983L;

	protected long        timestamp; // id 1#3, milliseconds since 1970
	protected PairProduct pair;      // id 2#3,
	protected BookSide    side;      // id 3#3, affected side 

	protected Rate thisSideRate;
	protected Rate otherSideRate;
	protected Rate thisSidePrevRate;

	
	public AbsOBState(long timestamp, PairProduct pair, BookSide side,
			Rate thisSideRate, Rate otherSideRate, Rate thisSidePrevRate) {
		super();
		this.timestamp = timestamp;
		this.pair = pair;
		this.side = side;
		this.thisSideRate = thisSideRate;
		this.otherSideRate = otherSideRate;
		this.thisSidePrevRate = thisSidePrevRate;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public PairProduct getPair() {
		return pair;
	}

	public BookSide getSide() {
		return side;
	}

	public Rate getThisSideRate() {
		return thisSideRate;
	}

	public Rate getOtherSideRate() {
		return otherSideRate;
	}

	public Rate getThisSidePreviousRate() {
		return thisSidePrevRate;
	}

	
	public Rate getBid() {
		if ( BookSide.BID.equals(side) ) {
			return thisSideRate;
		}
		return otherSideRate;
	}

	public Rate getOffer() {
		if ( BookSide.OFFER.equals(side) ) {
			return thisSideRate;
		}
		return otherSideRate;
	}

	public Rate getPreviousBid() {
		if ( BookSide.BID.equals(side) ) {
			return thisSidePrevRate;
		}
		return null;
	}
	
	public Rate getPreviousOffer() {
		if ( BookSide.OFFER.equals(side) ) {
			return thisSidePrevRate;
		}
		return null;
	}

	// gened with Eclipse on quoteId and timestamp, pair, side 
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((pair == null) ? 0 : pair.hashCode());
		result = prime * result + ((side == null) ? 0 : side.hashCode());
		result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
		return result;
	}

	// gened with Eclipse on quoteId and timestamp, pair, side 
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbsOBState other = (AbsOBState) obj;
		if (pair == null) {
			if (other.pair != null)
				return false;
		} else if (!pair.equals(other.pair))
			return false;
		if (side == null) {
			if (other.side != null)
				return false;
		} else if (!side.equals(other.side))
			return false;
		if (timestamp != other.timestamp)
			return false;
		return true;
	}

	protected String additionalToString() {
		return 
			  ", thisSideRate=" + thisSideRate
			+ ", otherSideRate=" + otherSideRate
			+ ", thisSidePrevRate=" + thisSidePrevRate
		;
	}
	
	@Override
	public String toString() {
		return getClass().getSimpleName() 
			+  "[side=" + side 
			+ ", pair=" + pair.getName()
			+ ", timestamp=" + timestamp
			+ additionalToString()
			+ "]";
	}
	
}
